import ShareInterface from "../base/ShareInterface";
import PlaneManager from "../../game/public/PlaneManager";
export default class WXShare implements ShareInterface{


    constructor(){

        wx.showShareMenu({
          withShareTicket:true,
        });
        wx.updateShareMenu({
          withShareTicket: true
        })        
        wx.onShareAppMessage(function () {
            // 用户点击了“转发”按钮
            let visibleOrigin = cc.view.getVisibleOrigin();
            let visibleSize = cc.view.getFrameSize();

            return {
              title: PlaneManager.instance().getLangManager().getLocalString('ui.share_menu'),
              imageUrl: canvas.toTempFilePathSync({
                x:visibleOrigin.x,
                y:visibleOrigin.y,
                destWidth: visibleSize.width,
                destHeight: visibleSize.height
              })                  
            }
          })
    }

    share(title:string,func?:Function){
        let visibleOrigin = cc.view.getVisibleOrigin();
        let visibleSize = cc.view.getFrameSize();
        cc.log('shareAppMessage title ',title)
        wx.shareAppMessage({
            title: title,
            x:visibleOrigin.x,
            y:visibleOrigin.y,            
            imageUrl: canvas.toTempFilePathSync({
                destWidth: visibleSize.width,
                destHeight: visibleSize.height
              })            
          })   
    }

    getShareInfo(shareTicket:string, func:(result)=>void){
      if(shareTicket){
        wx.getShareInfo({
          shareTicket:shareTicket,
          success:()=>{
            
          },
          fail:()=>{
  
          }
        });
      }

    }

}
